// custom-tab-bar/index.js
import { storeBindingsBehavior } from "mobx-miniprogram-bindings";
import { store } from "../store/store";
// const skinBehavior = require("../utils/skinBehavior");
Component({
  options: {
    styleIsolation: "shared",
  },
  behaviors: [storeBindingsBehavior],
  storeBindings: {
    store,
    fields: {
      sum: "sum",
      active: "activeTabBarIndex",
    },
    actions: {
      updateActive: "updateActiveTabBarIndex",
    },
  },
  // observers: {
  //   sum: function (val) {
  //     this.setData({
  //       "list[1].info": val,
  //     });
  //   },
  // },
  /**
   * 组件的属性列表
   */
  // behaviors: [skinBehavior],
  properties: {},

  /**
   * 组件的初始数据
   */
  lifetimes: {
    attached(option) {
      let that = this
      // setTimeout(() => {
      //   console.log('tab设置data')
      //   console.log(that.data)
      //   // console.log("option: ", option);
      //   console.log("前缀", that.data.themeStyleObj);
      //   that.setData({
      //     list: [
      //       {
      //         pagePath: "/pages/home/home",
      //         text: "首页",
      //         iconPath: `${that.data.themeStyleObj.imagesFile}/images/tabs/home.png`,
      //         selectedIconPath: `${that.data.themeStyleObj.imagesFile}/images/tabs/home-active.png`,
      //       },
      //       {
      //         pagePath: "/pages/theme/theme",
      //         text: "主题",
      //         iconPath: `${that.data.themeStyleObj.imagesFile}/images/tabs/theme.png`,
      //         selectedIconPath: `${that.data.themeStyleObj.imagesFile}/images/tabs/theme-active.png`,
      //       },
      //       {
      //         pagePath: "/pages/rankList/rankList",
      //         text: "排行榜",
      //         iconPath: `${that.data.themeStyleObj.imagesFile}/images/tabs/rankList.png`,
      //         selectedIconPath: `${that.data.themeStyleObj.imagesFile}/images/tabs/rankList-active.png`,
      //       },
      //       {
      //         pagePath: "/pages/my/my",
      //         text: "我的",
      //         iconPath: `${that.data.themeStyleObj.imagesFile}/images/tabs/my.png`,
      //         selectedIconPath: `${that.data.themeStyleObj.imagesFile}/images/tabs/my-active.png`,
      //       },
      //     ]
      //   })
      // }, 500)
    },
    detached() {
      // console.log("豆豆的");
    },
  },
  data: {
    list: [
      {
        pagePath: "/pages/home/home",
        text: "首页",
        iconPath: `/images/tabbar/index.png`,
        selectedIconPath: `/images/tabbar/index-selected.png`,
      },
      {
        pagePath: "/pages/my/my",
        text: "我的",
        iconPath: `/images/tabbar/my.png`,
        selectedIconPath: `/images/tabbar/my-selected.png`,
      },
    ],
    pre: "",
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onChange(event) {
      console.log("data", this.data);
      // console.log("skinBehavior", this.data.themeStyleObj.imagesFile);
      console.log("event: ", event);
      // event.detail 的值为当前选中项的索引
      // this.setData({ active: event.detail })
      this.updateActive(event.detail);
      wx.switchTab({
        url: this.data.list[event.detail].pagePath,
      });
    },
  },
});
